package com.banshuibao.bsb_android.util;

import android.content.Context;
import android.content.SharedPreferences;

import com.banshuibao.bsb_android.MyApplication;


/**
 * Created by Administrator on 2017/3/20.
 */

public class GetLoginInfo {

    private Context context;
    //登录cookieId
    private String cookieId;
    //姓名
    private String name;

    private String firmId;
    //头像
    private String headImg;
    //手机号
    private String phoneNumber;
    //用户的角色（0 事务所用户 1解税宝用户 2 事务所管理员 3 咨询师 4 专家）
    private String role;
    //是否是会员：0 是 1 不是
    private String vip;
    //余额
    private float balance;
    //会员过期时间
    private long vipTime;

    private String position;

    private String duty;

    //事务所名称
    private String firmName;

    private String rapidLimit;

    private String userId;

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getRapidLimit() {
        return rapidLimit;
    }

    public void setRapidLimit(String rapidLimit) {
        this.rapidLimit = rapidLimit;
    }

    public String getFirmName() {
        return firmName;
    }

    public String getPosition() {
        return position;
    }

    public String getCookieId() {
        return cookieId;
    }

    public String getName() {
        return name;
    }

    public String getFirmId() {
        return firmId;
    }

    public String getHeadImg() {
        return headImg;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public String getRole() {
        return role;
    }

    public String getVip() {
        return vip;
    }

    public float getBalance() {
        return balance;
    }

    public long getVipTime() {
        return vipTime;
    }

    public String getDuty() {
        return duty;
    }

    public void setDuty(String duty) {
        this.duty = duty;
    }

    private static GetLoginInfo getLoginInfo;

    private GetLoginInfo(Context context) {
        this.context = context;
    }

    public synchronized static GetLoginInfo getLoginInfoInstance(Context context) {
        if (getLoginInfo != null)
            return getLoginInfo;
        return new GetLoginInfo(context);
    }

    public GetLoginInfo readUser() {
        readLoginInfo();
        return this;
    }

    //获取登录成功保存信息
    private void readLoginInfo() {
        SharedPreferences sharedPre = MyApplication.applicationInstance.getSharedPreferences("registerInFo", Context.MODE_PRIVATE);
        cookieId = sharedPre.getString("cookieId", "");
        name = sharedPre.getString("name", "");
        firmId = sharedPre.getString("firmId", "");
        headImg = sharedPre.getString("headImg", "");
        phoneNumber = sharedPre.getString("phoneNumber", "");
        role = sharedPre.getString("role", "");
        vip = sharedPre.getString("vip", "");
        balance = sharedPre.getFloat("balance", 0);
        vipTime = sharedPre.getLong("vipTime", 0);
        position = sharedPre.getString("position","");
        duty = sharedPre.getString("duty","");
        firmName = sharedPre.getString("firmName","");
        rapidLimit = sharedPre.getString("rapidLimit","");
        userId = sharedPre.getString("userId","");
    }

    public void saveInfo(String rapidLimit ){
        SharedPreferences.Editor editor = MyApplication.applicationInstance.getSharedPreferences("registerInFo", Context.MODE_PRIVATE).edit();
        editor.putString("rapidLimit",rapidLimit);//是否启用悬赏：0 启用 1 不启用
        editor.commit();
    }

    //清除信息
    public void clearInfo() {
        SharedPreferences.Editor editor = MyApplication.applicationInstance.getSharedPreferences("registerInFo", Context.MODE_PRIVATE).edit();
        editor.clear().commit();
        MyApplication.applicationInstance.restCookieId();
    }
}
